const getLocalStorageItem = <T>(key: string): T | null => {
    const item = localStorage.getItem(key);
    if (item) {
      try {
        // 尝试将 localStorage 中的值解析为 JSON 对象
        return JSON.parse(item) as T;
      } catch (error) {
        // 解析失败则返回 null
        console.error('Error parsing localStorage item:', error);
        return null;
      }
    }
    return null;
  };


const TOKENKEY='token_key'
// getToken
const getToken =()=>{
 return localStorage.getItem(TOKENKEY)
}

// setToken
const setToken =(token:string)=>{
  localStorage.setItem(TOKENKEY,token)
}

// removeToken
const removeToken =()=>{
  localStorage.removeItem(TOKENKEY)
}

export {
  getToken,setToken,removeToken
}